﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;
using BusinessObjects;
using System.Globalization;

namespace MainGameModule.Views.Converters
{
    public class GameObjectToViewConverter : IValueConverter
    {
        public object Convert( object value, Type targetType, object parameter, CultureInfo culture )
        {
            if ( value is GameObject == false )
                return null;

            GameObject gameObject = value as GameObject;

            if ( gameObject is Player )
            {
                Player player = gameObject as Player;

                KidControl control = new KidControl();
                control.CountOfImages = 8;
                control.Direction = MoveDirection.Right;
                control.FramesPerSecond = 6;
                control.IsMoving = true;
                control.Player = player;

                return control;
            }

            Quest quest = gameObject as Quest;

            if ( quest != null && quest.QuestType == BuildQuestTypes.WaterPlant )
            {
                SplineAnimation questControl = new SplineAnimation();
                questControl.ImagesDirectory = @"images/waterplant"; // quest.ImagesDirectory;
                questControl.AutoReverse = true;
                questControl.Width = 160;
                questControl.FramesPerSecond = 10;
                questControl.CountOfImages = 13;
                questControl.ImagesCommonPattern = "WaterPlant000";
                questControl.ImagesExtention = "png";

                return questControl;
            }

            if ( quest != null )
            {
                return new ImageObjectView( gameObject );
            }

            gameObject.Image = "images/" + gameObject.Image;
            return new ImageObjectView( gameObject );
        }

        public object ConvertBack( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture )
        {
            throw new NotImplementedException();
        }

    }
}
